package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.mapper.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManageServiceImpl implements ManageService {
    //需要调用mapper层
    @Autowired
    private BaseCategory1Mapper baseCategory1Mapper;

    @Autowired
    private BaseCategory2Mapper baseCategory2Mapper;

    @Autowired
    private BaseCategory3Mapper baseCategory3Mapper;

    @Autowired
    private BaseAttrInfoMapper baseAttrInfoMapper;

    @Autowired
    private BaseAttrValueMapper baseAttrValueMapper;

    @Override
    public List<BaseCategory1> GetCategory1() {
        //select *from base_category1
        return baseCategory1Mapper.selectList(null);
    }

    @Override

    public List<BaseCategory2> GetCategory2(Long category1Id) {
        //select *from base_category2 where category1_id=?
        return baseCategory2Mapper.selectList(new QueryWrapper<BaseCategory2>().eq("category1_id",category1Id));
    }

    @Override
    public List<BaseCategory3> GetCategory3(Long category2Id) {
        //select *from base_category3 where category2_id =？
        return baseCategory3Mapper.selectList(new QueryWrapper<BaseCategory3>().eq("category2_id",category2Id));
    }

    @Override
    public List<BaseAttrInfo> getAttrInfoList(Long category1Id, Long category2Id, Long category3Id) {
        /*
        select * from base_attr_info bai inner join base_attr_value bav
								on bai.id = bav.attr_id
							where (category_id = ? and category_level = 1)
															or (category_id = ? and category_level = 2 )
															or (category_id = ? and category_level = 3 );
			涉及到两张表关联查询 可以使用mapper.xml 配置文件
         */
        return baseAttrInfoMapper.selectAttrInfoList(category1Id,category2Id,category3Id);
    }


}
